<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2021/4/1
  Time: 15:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册页面</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body class="login-bg">

<div class="login">
    <div class="message">酒店管理系统-管理注册</div>
    <div id="darkbannerwrap"></div>

    <hr class="hr15">

    <form class="layui-form">
        <input name="username" id="username" placeholder="用户名" type="text" class="layui-input">
        <hr class="hr15">
        <input name="password" id="password" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <input name="cPassword" id="cPassword" placeholder="确认密码" type="password" class="layui-input">
        <hr class="hr15">
        <input name="email" id="email" type="email" placeholder="邮箱" class="layui-input">
        <hr class="hr15">

        <input type="text" class="layui-input layui-input layui-col-sm2" style="width: 50%;display: inline" id="code">
        <div id="send">
            <button id="btn" type="button" style="margin-left: 10px;" class="layui-btn layui-btn-xs"
                    onclick="sendCode()">发送验证码
            </button>
        </div>
        <hr class="hr15">
        <input value="注册" onclick="userLogin()" style="width:100%;" type="button">
        <hr class="hr15">
        <span id="info" style="color: red"></span>

        <hr class="hr20">
    </form>
</div>

<script>
    function userLogin() {
        var name = $("#username").val();
        var pwd = $("#password").val();
        var cPwd=$("#cPassword").val();
        var code=$("#code").val();
        if (pwd != cPwd) {
            $("#info").text("密码与确认密码不一致！");
        } else {
            $.ajax({
                url: "${pageContext.request.contextPath}/login/regist",
                type: "post",
                data: {"userName": name, "userPassword": pwd,"code":code},
                contentType: "application/x-www-form-urlencoded",
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.info == "注册成功") {
                        window.location.href = "${pageContext.request.contextPath}/exit";
                        alert(data.info+",请重新登录");
                    } else {
                        $("#info").text(data.info);
                    }

                }
            });
        }

    }

    //计时器秒
    var s = 30

    function sendCode() {
        var email=$("#email").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/login/sendCodeAjx",
            type: "post",
            data: {"email":email},
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function (data) {
                console.log(data);
                $("#info").text(data.info);
            }
        });
        var time = setInterval(function () {
            //禁用发送验证码按钮
            $("#send").html("<button type='button'  class='layui-btn layui-btn-disabled layui-btn-small' >" + s + "秒后发送验证码</button>")
            s--;
            if (s == 0) { //倒计时结束
                //清除计时器
                clearInterval(time);
                //启用发送验证码
                $("#send").html("<button type='button' class='layui-btn'>发送验证码</button>")
            }


        }, 1000)



    }
</script>

</body>
</html>
